import Vue from 'vue'
import Router from 'vue-router'
import indexPage from '@/pages/index/Index.vue'
import farmPage from '@/pages/farm/Index.vue'
import farmListPage from '@/pages/farm/list.vue'
import centerPage from '@/pages/my/Index.vue'
import vipPage from '@/pages/vip/Index.vue'
const ErroPage = resolve => require(['@/common/ErroPage'], resolve)

Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/index'
    },
    {
      path: '/index',
      name: 'indexPage',
      component: indexPage,
      meta: {
        keepAlive: false,
        title: '首页'
      }
    },
    {
      path: '/farm',
      name: 'farmPage',
      component: farmPage,
      meta: {
        keepAlive: false,
        title: '农家鲜'
      }
    },
    {
      path: '/farm/list',
      name: 'farmListPage',
      component: farmListPage,
      meta: {
        keepAlive: false,
        title: '农家鲜列表'
      }
    },
    {
      path: '/travel',
      name: 'travelListPage',
      component: () => import('@/pages/travel/Index.vue'),
      meta: {
        keepAlive: false,
        title: '列表'
      }
    },
    {
      path: '/travel/:id',
      name: 'travelDetailPage',
      component: () => import('@/pages/travel/detail.vue'),
      meta: {
        keepAlive: false,
        title: '详情'
      }
    },
    {
      path: '/njx',
      name: 'njxPage',
      component: () => import('@/pages/njx/Index.vue'),
      meta: {
        keepAlive: false,
        title: '农佳鲜'
      }
    },
    {
      path: '/jhs',
      name: 'jhsPage',
      component: () => import('@/pages/jhs/Index.vue'),
      meta: {
        keepAlive: false,
        title: '聚划算'
      }
    },
    {
      path: '/acti',
      name: 'actiPage',
      component: () => import('@/pages/activity/apply.vue'),
      meta: {
        keepAlive: false,
        title: '活动中心'
      }
    },
    {
      path: '/pasture',
      name: 'pasturePage',
      component: () => import('@/pages/old/Index.vue'),
      meta: {
        keepAlive: false,
        title: '候鸟式养老'
      }
    },
    {
      path: '/center',
      name: 'centerPage',
      component: centerPage,
      meta: {
        keepAlive: true,
        title: '我的'
      }
    },
    {
      path: '/vip',
      name: 'VipPage',
      component: vipPage,
      meta: {
        keepAlive: true,
        title: '会员'
      }
    },
    {
      path: '*',
      component: ErroPage,
      meta: {
        keepAlive: true,
        title: '找不到页面',
        index: 1
      }
    }
  ],
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop
      }
      return { x: 0, y: to.meta.savedPosition || 0 }
    }
  }
})
